package com.iretailer.report.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @Auther: xjw
 * @Date: 2019/1/21 17:24
 * @Description:
 */
public class MD5Util {

    public static String getMd5(String plainText) {
        String result = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes());
            byte[] bytes = md.digest();
            int b = 0;
            StringBuilder buf = new StringBuilder("");
            for (int offset  = 0, len = bytes.length; offset  < len; offset ++) {
                b = bytes[offset];
                if (b < 0) {
                    b += 256;
                }
                if (b < 16) {
                    buf.append("0");
                }
                buf.append(Integer.toHexString(b));
            }
            result = buf.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } finally {
            return result;
        }
    }


    public static void main(String[] args) {
        System.out.println(MD5Util.getMd5("admin"));
    }
}
